package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.SysRoleMenu;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.ISysRoleMenuService;
import com.zuipin.util.Pagination;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 角色-菜单(权限)Controller
 * 
 * @ClassName: SysRoleMenuController
 * @Description: TODO
 * @author robot
 * @date 2017年09月147日 09:21:09
 */
@Api(value = "角色-菜单(权限)", description = "角色-菜单(权限)")
@RestController
@RequestMapping(value = "/sysRoleMenu")
public class  SysRoleMenuController {
	@Resource
	public ISysRoleMenuService sysRoleMenuService;

	
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ApiOperation(value = "根据主键查询角色-菜单(权限)", notes = "查询角色-菜单(权限)")
	public Result<SysRoleMenu> getSysRoleMenuById(@ApiParam(required = true, name = "id", value = "主键 自增长") @RequestParam Long id){
		SysRoleMenu sysRoleMenu = sysRoleMenuService.findById(id);
		Result<SysRoleMenu> result = new Result<SysRoleMenu>();
		if (sysRoleMenu != null) {
			result.setData(sysRoleMenu);
			result.setErrorCode(ErrorCode.SUCCESS);
		} else {
			result.setErrorCode(ErrorCode.ELSE);
		}
		return result;
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ApiOperation(value = "新增角色-菜单(权限)", notes = "新增角色-菜单(权限)")
	@Valids({
		
		@Valid(name = "sysRoleMenu.roleId",  maxLength = 10),
		@Valid(name = "sysRoleMenu.menuId",  maxLength = 10),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysRoleMenu.roleId", value = "角色id", required = true, dataType = "roleId", paramType = "query"),
		@ApiImplicitParam(name = "sysRoleMenu.menuId", value = "菜单(模块)id", required = true, dataType = "menuId", paramType = "query"),
	})
	public Result<SysRoleMenu> insertSysRoleMenu(@Inject @ApiIgnore SysRoleMenu sysRoleMenu) {
		Result<SysRoleMenu> result = new Result<SysRoleMenu>();
		sysRoleMenuService.insert(sysRoleMenu);
		result.setData(sysRoleMenu);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ApiOperation(value = "根据主键修改角色-菜单(权限)", notes = "修改角色-菜单(权限)")
	@Valids({ 
		@Valid(name = "sysRoleMenu.id",  maxLength = 19),
		@Valid(name = "sysRoleMenu.roleId",  maxLength = 10),
		@Valid(name = "sysRoleMenu.menuId",  maxLength = 10),
	})
	@ApiImplicitParams({
		@ApiImplicitParam(name = "sysRoleMenu.id", value = "主键 自增长", required = true, dataType = "id", paramType = "query"),
		@ApiImplicitParam(name = "sysRoleMenu.roleId", value = "角色id", required = true, dataType = "roleId", paramType = "query"),
		@ApiImplicitParam(name = "sysRoleMenu.menuId", value = "菜单(模块)id", required = true, dataType = "menuId", paramType = "query"),
	})
	public Result<SysRoleMenu> updateSysRoleMenu(@Inject @ApiIgnore SysRoleMenu sysRoleMenu) {
		Result<SysRoleMenu> result = new Result<SysRoleMenu>();
		sysRoleMenuService.update(sysRoleMenu);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/del", method = RequestMethod.DELETE)
	@ApiOperation(value = "根据主键删除角色-菜单(权限)", notes = "删除角色-菜单(权限)")
	public Result<SysRoleMenu> delSysRoleMenu( Long id) {
		Result<SysRoleMenu> result = new Result<SysRoleMenu>();
		sysRoleMenuService.delete(id);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/seach", method = RequestMethod.POST)
	@ApiOperation(value = "搜索角色-菜单(权限)SKU角色-菜单(权限)并分页", notes = "搜索角色-菜单(权限)并分页")
	@Valids({
		
		@Valid(name = "sysRoleMenu.roleId",  maxLength = 10),
		@Valid(name = "sysRoleMenu.menuId",  maxLength = 10),
		@Valid(name = "page.pageNumber",  maxValue = 999),
		@Valid(name = "page.pageSize",  maxValue = 999),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "sysRoleMenu.roleId", value = "角色id", required = true, dataType = "roleId", paramType = "query"),
		@ApiImplicitParam(name = "sysRoleMenu.menuId", value = "菜单(模块)id", required = true, dataType = "menuId", paramType = "query"),
		@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"),
	})
	public Result<List<SysRoleMenu>> seachSysRoleMenu(@Inject @ApiIgnore SysRoleMenu sysRoleMenu,
			@Inject @ApiIgnore Pagination page) {
		PageResult<List<SysRoleMenu>> result = new PageResult<List<SysRoleMenu>>();
		result.setData(sysRoleMenuService.seachSysRoleMenu(sysRoleMenu, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
